package com.lagou.demo.controller;

import com.lagou.demo.service.IDemoService;
import com.lagou.edu.mvcframework.annotations.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@LagouController
@LagouRequestMapping("/demo")
public class DemoController {


    @LagouAutowired
    private IDemoService demoService;


    /**
     * URL: /demo/query?name=lisi
     * @param request
     * @param response
     * @param name
     * @return
     */
    @LagouRequestMapping("/query")
    @LagouResponseBody
    public String query(HttpServletRequest request, HttpServletResponse response,String name) {
        return demoService.get(name);
    }

    /**
     * 校验成功   http://localhost:8080/demo/auth/test1?username=zhangsan
     * 校验失败   http://localhost:8080/demo/auth/test1?username=zhang
     * @return
     */
    @Security(value = {"zhangsan","lisi"})
    @LagouRequestMapping("/auth/test1")
    @LagouResponseBody
    public String authTest1(HttpServletRequest request, HttpServletResponse response, String username) {
        return username + " login success";
    }

    /**
     * 校验成功   http://localhost:8080/demo/auth/test2?username=housailei
     * 校验失败   http://localhost:8080/demo/auth/test2?username=zhang
     * @return
     */
    @Security(value = {"housailei","luobinghan"})
    @LagouRequestMapping("/auth/test2")
    public String authTest2(HttpServletRequest request, HttpServletResponse response) {
        return "/index.jsp";
    }
}
